#define _CRT_SECURE_NO_WARNINGS 1
#include"Stack.h"


void StackInit(Stack* st)
{
	assert(st);
	st->top = 0;
	st->p = (StackType*)malloc(INIT_NUM * sizeof(StackType));
	assert(st->p);
	st->capcity = INIT_NUM;
}
void StackPush(Stack* st, StackType x)
{
	assert(st);
	if (st->capcity == st->top)
	{
		StackType*  ret=(StackType*)realloc(st->p,2*INIT_NUM * sizeof(StackType));
		assert(ret);
		st->p = ret;
		st->capcity *= 2;

	}
	st->p[st->top++] = x;
}
void StackPop(Stack* st)
{
	assert(st);
	assert(!Stackempty(st));
	st->top--;

}
void StackDestroy(Stack* st)
{
	assert(st);
	free(st->p);
	st->capcity = 0;
	st->top = 0;
}

StackType StackTop(Stack* st)
{
	assert(st);
	assert(!Stackempty(st));
	return st->p[st->top - 1];

}
int StackSize(Stack* st)
{
	assert(st);
	return st->top;
}
bool Stackempty(Stack* st)
{
	assert(st);
	return st->top == 0;
}
